package com.study.spmongodb.book.wwj.char17;

/**
 * @author MI
 * @version 1.0
 * @date 2020/11/29 10:06
 */
public class ReadWriteLockImpl implements ReadWriteLock {
    //定义锁对象
    private final Object MUTEX = new Object();
    //当前有多少个线程正在写入
    private int writingWritiers = 0;

    //当前有多少个线程正在等待写入
    private int waitingWriters = 0;

    //当前有多少个线程正在read
    private int readingReaders = 0;

    public Object getMUTEX() {
        return this.MUTEX;
    }

    //获取当前是否偏向锁
    boolean getPreferWriter() {
        return this.preferWriter;
    }

    //设置写锁偏好
    void changePrefer(boolean preferWriter) {
        this.preferWriter = preferWriter;
    }

    //read和write 的偏好设置
    private boolean preferWriter;


    public ReadWriteLockImpl(boolean preferWriter) {
        this.preferWriter = preferWriter;
    }

    public ReadWriteLockImpl() {
        this(true);
    }

    public Lock readLock() {
        return new ReadLock(this);
    }


    @Override
    public Lock writeLock() {
        return null;
    }

    @Override
    public int getWritingWriters() {
        return 0;
    }

    @Override
    public int getWaitingWrtiers() {
        return 0;
    }

    @Override
    public int getReadingReaders() {
        return 0;
    }
}
